[% setvar title Lazy Input / Context-sensitive Input %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Lazy Input / Context-sensitive Input</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Adam Turoff &lt;<a href='mailto:ziggy@panix.com'>ziggy@panix.com</a>&gt;
  Date: 24 Sep 2000
  Last Modified: 26 Sep 2000
  Mailing List: <a href='mailto:perl6-language@perl.org'>perl6-language@perl.org</a>
  Number: 285
  Version: 2
  Status: Frozen</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>Currently, file read operations work in either scalar context or list
context.  When the left-hand-side of an input operation contains a finite
list of scalars, a finite number of records should be returned, rather than
reading all of the records and losing most of them.</p>
<a name='NOTES'></a><h1>NOTES</h1>
<p>Damian mentioned that this &quot;tricky&quot; bit of magic is trivial with his
proposed context sensitive want() function.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>Tom Christiansen proposed this in his perl6storm message:</p>
<pre>	=item perl6storm #0000

	This:

		($a,$b) = &lt;FH&gt;;  

	should not drain whole ahndle on known LHS count, to rescue

		my($x) = &lt;FH&gt;;</pre>
<p>As Tom points out, this is an accidental misfeature, caused by enabling</p>
<pre>	@lines = &lt;FH&gt;;</pre>
<p>to be sensible.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>Not so tricky, if RFC 21 is implemented.</p>
<p>In order for I/O operations (or any function) to emit the proper
number of return values in each of the following cases:</p>
<pre>	$x = foo();

	($x) = foo();

	($x, $y) = foo();

	($x, $y, ...) = foo();

	@values = foo();</pre>
<p>The function in question needs to return values in a manner similar
to this RFC 21-inspired bit of pseudo code:</p>
<pre>	if (want &quot;SCALAR&quot;) {
		return next_singleton();
	} elsif ($count = want &quot;COUNT&quot;) {
		my @list;
		push(@list, next_singleton()) for (1..$count);
		return @list;
	} elsif(want &quot;LIST&quot;) {
		my @list;
		my $singleton;
		while (defined($singleton = next_singleton())) {
			push(@list, $singleton);
		}
		return (@list)
	}

	... ## More contexts to follow.  These three cover intelligent I/O.</pre>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>RFC 21: Subroutines: Replace <code>wantarray</code> with a generic <code>want</code> function</p>
<p>perl6storm</p>
</div>
